package com.hanxiaozhang.api.order.fegin.fallback;

import com.hanxiaozhang.api.order.fegin.OrderFeignClient;
import com.hanxiaozhang.exception.ResultCode;
import com.hanxiaozhang.order.entity.Order;
import com.hanxiaozhang.result.Result;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 〈一句话功能简述〉<br>
 * 〈〉
 *
 * @author hanxinghua
 * @create 2020/7/19
 * @since 1.0.0
 */
@Slf4j
@Component
public class OrderFeignClientFallbackFactory implements FallbackFactory<OrderFeignClient> {
    @Override
    public OrderFeignClient create(Throwable throwable) {

        return new OrderFeignClient() {
            @Override
            public Result findById(Long id) {
                log.info("into OrderFeignClientFallbackFactory-findById");
                return Result.error(ResultCode.HYSTRIX_FUSING,throwable, HttpStatus.INTERNAL_SERVER_ERROR);
            }

            @Override
            public Result save(Order order) {
                log.info("into OrderFeignClientFallbackFactory-findById");
                return Result.error(ResultCode.HYSTRIX_FUSING,throwable, HttpStatus.INTERNAL_SERVER_ERROR);
            }
        };
    }
}
